package niit.com.classtable;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Database(entities = {Course.class},version = 1,exportSchema = false)
public abstract class InfoRoomDatabase extends RoomDatabase {
    public static  String DB_NAME="courses.db";
    private static  volatile  InfoRoomDatabase INSTANCE;
    private static final int NUMBER_OF_THREADS=4;

    public abstract CourseDao getCourseDao();

    public static final ExecutorService writeExecutor= Executors.newFixedThreadPool(NUMBER_OF_THREADS);

    public static InfoRoomDatabase getInstance(final Context context){
        if (INSTANCE==null){
            synchronized (InfoRoomDatabase.class){
                if (INSTANCE==null){
                    INSTANCE= Room.databaseBuilder(context.getApplicationContext(),InfoRoomDatabase.class,InfoRoomDatabase.DB_NAME).allowMainThreadQueries().build();
                }
            }
        }
        return INSTANCE;
    }
public void cleanUp(){
        INSTANCE=null;
}
    @NonNull
    @Override
    protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
        return null;
    }

    @NonNull
    @Override
    protected InvalidationTracker createInvalidationTracker() {
        return null;
    }

    @Override
    public void clearAllTables() {

    }
}
